'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: 4_study_configurable_filed.py
* @Time: 2025/7/27
* @All Rights Reserve By Brtc
'''
from langchain_community.chat_models import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import ConfigurableField

"""5、Runnable 组件动态添加默认调用参数  a、configurable_fields 方法使用技巧"""
import dotenv
from langchain_core.prompts import ChatPromptTemplate

dotenv.load_dotenv()

#1、创建 提示词模板
prompt = ChatPromptTemplate.from_template("请生成一个小于{x}的随机数")
#2、创建大预言模型
llm = ChatOpenAI(model="gpt-3.5-turbo-16k").configurable_fields(
    temperature=ConfigurableField(
        id = "llm_tempersture",
        name="大预言模型参数",
        description="用于调整大预言模型生成的内容随机性"
    )
)

# 3、构建链应用
chain = prompt|llm|StrOutputParser()
content = chain.invoke({"x":1000})
print(content)
print("===============================")
cotent = chain.with_config(configurable={"llm_tempersture":0}).invoke({"x":1000})
print(cotent)